#include "../../../common/data_es.hpp"
#include<gflags/gflags.h>
DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es客户端url");

int main(int argc, char *argv[])
{

    google::ParseCommandLineFlags(&argc, &argv, true);
    bite_im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    std::vector<std::string> host_list = {FLAGS_es_host};
    auto es_client = bite_im::ElasticFactory::create(host_list);
    auto es_user = std::make_shared<bite_im::ESUser>(es_client);

    // 如果appendData和serarch时间差较小，会导致无法查询
    // search的时候appendData还没有构建好

    // es_user->createIndex();
    // es_user->appendData("2022044026", "13147065653", "陈钟", "我是梧桐树只因哥", "头像1");
    // es_user->appendData("432248", "17880730714", "陈志鸿", "我是藏起来的爱坤", "头像2");

    auto ret = es_user->search("陈", {"432248"});
    for (auto user : ret)
    {
        std::cout << user.user_id() << std::endl;
        // odb::nullable<std::string>字段 需要解引用
        std::cout << *user.phone() << std::endl;
        std::cout << *user.nickname() << std::endl;
        std::cout << *user.description() << std::endl;
    }
}